JuSeok

App Life Cycle

App Life Cycle

상태 변화에 따라 다른 동작을 처리하기 위한 App Delegate Method들이 있다.

Foreground & Background 포스트에서 앱의 상태에 대해 공부해본 적이 있었다. 이번에는 각각의 앱의 상태에 따른 동작을 처리하기 위한 함수들에 대해 알아보자.

앱이 처음 실행될 때

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool

앱이 처음 실행될 때 호출되는 함수이다.

active에서 inactive로 바뀔 때

func applicationWillResignActive(_ application: UIApplication)

앱이 실행중일 때 전화가 오거나, 잠금화면, 멀티테스킹 스크린으로 바뀌게 되면 해당 함수를 호출한다.

Background 상태일 때

func applicationDidEnterBackground(_ application: UIApplication)

앱이 Background 상태가 되면 호출된다. 보통 공유자원 해제, 유저 데이터 저장 등의 로직이 여기에 구현된다.

Background에서 Foreground로 이동될 때

func applicationWillEnterForground(_ appication: UIApplication)

앱이 Background에서 Foreground로 이동될 때 실행된다. API를 통해 앱의 상태를 갱신할 때 사용된다. (버전 체크 등)

앱이 active 상태가 되었을 때

func applicationDidBecomeActive(_ application: UIApplication)

앱이 종료될 때

func appicationWillTerminate(_ application: UIApplication)



참고자료

Tags